package com.leyou.common.advice;

import com.leyou.common.enums.ExceptionResult;
import com.leyou.common.exceptions.LyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice//try  相当于给controller添加一个try，之后邹catch处理
public class BasicExceptionAdvice {

    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }

    /*@ExceptionHandler(RuntimeException.class)//catch
    public ResponseEntity<String> hangleException(RuntimeException e){
        //我们暂定返回状态码为400，然后从异常中获取友好提示信息
        return ResponseEntity.status(400).body(e.getMessage());
    }*/
}
